package com.xx.ems.util.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

import org.springframework.stereotype.Component;

import com.xx.ems.util.EquipmentBase;

/**
 * @author xxx
 * @date 2014-1-27
 * @version 1.0
 * 描述: 设备基础工具类
 */
@Component(value="EquipmentBase")
public class EquipmentBaseImpl implements EquipmentBase {
	@Override
	public String generateCode() {
		Calendar ca = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String date = sdf.format(ca.getTime());
		Random ra = new Random();
		//nextInt(n)产生从0到n之间的随机数(含0,不含n)
		int num = 100 + ra.nextInt(900);
		//一般性编号
		String code = date + num;

		return code;
	}
	@Override
	public String generateEquipmentCode(String equiptype){
		Calendar ca = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String date = sdf.format(ca.getTime());
		Random ra = new Random();
		//nextInt(n)产生从0到n之间的随机数(含0,不含n)
		int num = 100 + ra.nextInt(900);
		//设备编号
		String equipmentcode = equiptype + date + num;
		
		return equipmentcode;
	}
}